﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

/// <summary>
/// Summary description for LoginDAL
/// </summary>
public class LoginDAL
{
    Connect conn;
    private SqlDataReader sqlReader;
    private SqlCommand sqlCommand;

	public LoginDAL()
	{
        conn = new Connect();
	}

    public int Login(int id, int p)
    {
        sqlCommand = new SqlCommand("pr_Login", conn.GetConnect());
        sqlCommand.CommandType = CommandType.StoredProcedure;
        sqlCommand.Parameters.AddWithValue("user_id", id);
        sqlCommand.Parameters.AddWithValue("pass", p);
        sqlReader = sqlCommand.ExecuteReader();
        sqlReader.Read();
        if (sqlReader.HasRows)
        {
            int roll = sqlReader.GetInt32(1);
            sqlReader.Close();
            return roll;
        }
        sqlReader.Close();
        return 0;
    }

    public int CheckUserId(int id)
    {
        sqlCommand = new SqlCommand("pr_Login1", conn.GetConnect());
        sqlCommand.CommandType = CommandType.StoredProcedure;
        sqlCommand.Parameters.AddWithValue("user_id", id);
        sqlReader = sqlCommand.ExecuteReader();
        sqlReader.Read();
        if (sqlReader.HasRows)
        {
            sqlReader.Close();
            return 1;
            
        }
        sqlReader.Close();
        return 0;
    }

    public void Lock_Acc(int id)
    {
        sqlCommand = new SqlCommand("pr_Lock_Acc", conn.GetConnect());
        sqlCommand.CommandType = CommandType.StoredProcedure;
        sqlCommand.Parameters.AddWithValue("user_id", id);
        sqlCommand.ExecuteNonQuery();
    }

    public voif Open_Acc(int id)
    {
        sqlCommand = new SqlCommand("pr_Open_Acc", conn.GetConnect());
        sqlCommand.CommandType = CommandType.StoredProcedure;
        sqlCommand.Parameters.AddWithValue("user_id", id);
        sqlCommand.ExecuteNonQuery();
    }
}
